Added support for ASCII PNM files. Note I haven't tested loaded ASCII PBM
authorMichael Fulbright <drmike@redhat.com>
Mon, 8 Nov 1999 17:15:19 +0000 (17:15 +0000)
committerMichael Fulbright <drmike@src.gnome.org>
Mon, 8 Nov 1999 17:15:19 +0000 (17:15 +0000)
1999-11-08  Michael Fulbright  <drmike@redhat.com>

* src/io-pnm.c pnm_read_ascii_scanline (): Added support for
ASCII PNM files. Note I haven't tested loaded ASCII PBM files because
I can't seem to find a utility to convert into this format.
Next is to add progressive loading support for the PNM format.

gdk-pixbuf/ChangeLog
gdk-pixbuf/io-pnm.c

index 2246a765bd7b0885d650837b17ce884556970b0e..58d014d87d5e76e51e4fc676026af2721d2fb50a 100644 (file)
@@ -1,3 +1,10 @@
+1999-11-08  Michael Fulbright  <drmike@redhat.com>
+
+       * src/io-pnm.c pnm_read_ascii_scanline (): Added support for
+       ASCII PNM files. Note I haven't tested loaded ASCII PBM files because
+       I can't seem to find a utility to convert into this format.
+       Next is to add progressive loading support for the PNM format.
+
 1999-11-07  Federico Mena Quintero  <federico@redhat.com>
 
        * doc/tmpl/gnome-canvas-pixbuf.sgml: Finished detailed explanation
index 32003b8decea6ba926b7fc3e714bd4ab783bda8f..04f71ce079a550185ca727f37ce11e583da80130 100644 (file)
@@ -329,8 +329,6 @@ pnm_read_header (PnmLoaderContext *context)
                return PNM_FATAL_ERR;
        }
        
-       g_print ("File format is %d\n", type);
-
        context->type = type;
 
        inbuf->next_byte  += 2;
@@ -349,8 +347,6 @@ pnm_read_header (PnmLoaderContext *context)
                return PNM_SUSPEND;
        }
        
-       g_print ("Dimensions are %d x %d\n", w, h);
-
        context->width  = w;
        context->height = h;
        
@@ -364,8 +360,6 @@ pnm_read_header (PnmLoaderContext *context)
                        inbuf->bytes_left = old_bytes_left;
                        return PNM_SUSPEND;
                }
-               
-               g_print ("Maximum component value is %d\n", context->maxval);
                break;
        default:
                break;
@@ -454,8 +448,7 @@ pnm_read_raw_scanline (PnmLoaderContext *context)
 static gint
 pnm_read_ascii_scanline (PnmLoaderContext *context)
 {
-       guint  numpix;
-       guint  numbytes, offset;
+       guint  offset;
        gint   rc;
        guint  value, numval, i;
        guchar data;
@@ -473,15 +466,16 @@ pnm_read_ascii_scanline (PnmLoaderContext *context)
 
        switch (context->type) {
        case PNM_FORMAT_PBM:
-               mask = 0x80;
-               data = 0;
                numval = 8;
+               offset = context->output_col/8;
                break;
        case PNM_FORMAT_PGM:
                numval = 1;
+               offset = context->output_col;
                break;
        case PNM_FORMAT_PPM:
                numval = 3;
+               offset = context->output_col*3;
                break;
                
        default:
@@ -489,53 +483,57 @@ pnm_read_ascii_scanline (PnmLoaderContext *context)
                return PNM_FATAL_ERR;
        }
 
-       old_next_byte  = inbuf->next_byte;
-       old_bytes_left = inbuf->bytes_left;
-       dptr = context->dptr;
+       dptr = context->dptr + offset;
 
-       for (i=0; i<numval; i++) {
-               if ((rc = read_next_number (inbuf, &value))) {
-                       inbuf->next_byte  = old_next_byte;
-                       inbuf->bytes_left = old_bytes_left;
-                       return PNM_SUSPEND;
+       while (TRUE) {
+               if (context->type == PNM_FORMAT_PBM) {
+                       mask = 0x80;
+                       data = 0;
                }
-               printf ("0x%x ", value);
-               fflush (stdout);
-
-               switch (context->type) {
-               case PNM_FORMAT_PBM:
-                       if (value)
-                               data |= mask;
-                       mask >>= 1;
+
+               old_next_byte  = inbuf->next_byte;
+               old_bytes_left = inbuf->bytes_left;
+               
+               for (i=0; i<numval; i++) {
+                       if ((rc = read_next_number (inbuf, &value))) {
+                               inbuf->next_byte  = old_next_byte;
+                               inbuf->bytes_left = old_bytes_left;
+                               return PNM_SUSPEND;
+                       }
+                       switch (context->type) {
+                       case PNM_FORMAT_PBM:
+                               if (value)
+                                       data |= mask;
+                               mask >>= 1;
                                
-                       break;
-               case PNM_FORMAT_PGM:
-                       *dptr++ = (guchar)(255.0*((double)value/(double)context->maxval));
-                       break;
-               case PNM_FORMAT_PPM:
-                       *dptr++ = (guchar)(255.0*((double)value/(double)context->maxval));
-                       break;
-               default:
-                       g_warning ("io-pnm.c: Illegal raw pnm type!\n");
-                       break;
+                               break;
+                       case PNM_FORMAT_PGM:
+                               *dptr++ = (guchar)(255.0*((double)value/(double)context->maxval));
+                               break;
+                       case PNM_FORMAT_PPM:
+                               *dptr++ = (guchar)(255.0*((double)value/(double)context->maxval));
+                               break;
+                       default:
+                               g_warning ("io-pnm.c: Illegal raw pnm type!\n");
+                               break;
+                       }
                }
-       }
-
-       if (context->type == PNM_FORMAT_PBM)
-               *dptr++ = value;
-
-       context->output_col++;
-       if (context->output_col == context->width) {
-               if ( context->type == PNM_FORMAT_PBM_RAW )
-                       explode_bitmap_into_buf(context);
-               else if ( context->type == PNM_FORMAT_PGM_RAW )
-                       explode_gray_into_buf (context);
                
-               context->output_col = 0;
-               context->output_row++;
+               if (context->type == PNM_FORMAT_PBM)
+                       *dptr++ = value;
                
-       } else {
-               return PNM_SUSPEND;
+               context->output_col++;
+               if (context->output_col == context->width) {
+                       if ( context->type == PNM_FORMAT_PBM )
+                               explode_bitmap_into_buf(context);
+                       else if ( context->type == PNM_FORMAT_PGM )
+                               explode_gray_into_buf (context);
+
+                       context->output_col = 0;
+                       context->output_row++;
+                       break;
+               }
+
        }
 
        return PNM_OK;
@@ -563,14 +561,10 @@ pnm_read_scanline (PnmLoaderContext *context)
        case PNM_FORMAT_PBM:
        case PNM_FORMAT_PGM:
        case PNM_FORMAT_PPM:
-#if 0
-
                rc = pnm_read_ascii_scanline (context);
                if (rc == PNM_SUSPEND)
                        return rc;
                break;
-#endif
-               
 
        default:
                g_print ("Cannot load these image types (yet)\n");
@@ -590,11 +584,6 @@ image_load (FILE *f)
        PnmLoaderContext context;
        PnmIOBuffer *inbuf;
 
-
-#if 0
-       G_BREAKPOINT();
-#endif
-
        /* pretend to be doing progressive loading */
        context.updated_func = context.prepared_func = NULL;
        context.user_data = NULL;
@@ -643,8 +632,6 @@ image_load (FILE *f)
 
                /* scan until we hit image data */
                if (!context.did_prescan) {
-                       
-                       g_print ("doing prescan\n");
                        if (skip_ahead_whitespace (inbuf) == NULL)
                                continue;
 
@@ -656,8 +643,6 @@ image_load (FILE *f)
                                           context.width * 3);
                        if (!context.pixels)
                                return NULL;
-
-                       g_print ("prescan complete\n");
                }
 
                /* if we got here we're reading image data */